﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Actuals.CoreDomain;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;
using Actuals.Business;
using Actuals.Common;


namespace Actuals
{
    public partial class AddEmployeeLeaves : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                IBusinessEmployee businessEmployee = new BusinessEmployee();
                IList<IEmployee> employees = businessEmployee.GetEmployees();
                ddlEmployee.DataSource = employees;
                ddlEmployee.DataTextField = "NickName";
                ddlEmployee.DataValueField = "Id";
                ddlEmployee.DataBind();
            }


        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                IEmployeeLeave employeeLeave = new EmployeeLeave();
                IEmployeeLeaveUI employeeLeaveUI = new EmployeeLeaveUI();
                IBusinessEmployeeLeave businessEmployeeLeave = new BusinessEmployeeLeave();
                employeeLeave.EmpId = int.Parse(ddlEmployee.Text);
                employeeLeave.LeaveType = ddlLeaveType.Text;
               // string[] _fromDate = txtFromDate.Text.Split('-');
                employeeLeaveUI.FromDate = DateTime.Parse(txtFromDate.Text);
                    //new DateTime(int.Parse(_fromDate[2]), int.Parse(_fromDate[0]), int.Parse(_fromDate[1]));
                   
               // string[] _toDate = txtToDate.Text.Split('-');
                employeeLeaveUI.ToDate = DateTime.Parse(txtToDate.Text);
                    //new DateTime(int.Parse(_toDate[2]), int.Parse(_toDate[0]), int.Parse(_toDate[1]));





               


                employeeLeaveUI.AM = rdbtnAm.Checked;
                employeeLeaveUI.PM = rdbtnPm.Checked;
                employeeLeaveUI.ToAM = rdbtnam1.Checked;
                employeeLeaveUI.ToPM = rdbtnpm1.Checked;
                employeeLeaveUI.LeaveType = ddlLeaveType.SelectedValue;
                businessEmployeeLeave.ValidateEmployeeLeave(employeeLeave, employeeLeaveUI);
                lblMsg.Text = "Saved";
            }
            catch(Exception ex)
            {
                lblMsg.Text = ex.Message;
            }

        }
    }
}